<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>打印</title>
    <link rel="shortcut icon" href="../lib/image/favicon.ico" type="image/x-icon">
    <link rel="stylesheet" href="../lib/css/all.css">

    <script src="../lib/js/jquery-3.3.1.min.js"></script>
</head>

<body>
    <div id="app">
        <div id="nk" style="font-family: pingfangBold;">

        </div>

        <div style="width: 850px;margin: 20px;">
            <button type="button" onclick="PagesPrint()">打印</button>
        </div>
    </div>
</body>
<script>
    for (var i = 0; i < 10; i++) {
        $("#nk").append('<p style="margin:0;height: 40px;">' + i + '</p>')
    }

    function PagesPrint() {
        var newWindow = window.open("打印窗口", "_blank");
        var docStr = $("#nk")[0].innerHTML;

        newWindow.document.write(docStr);
        newWindow.document.close();
        newWindow.print();
        newWindow.close()

    }
</script>

</html>